package com.itheima.mall.controller;

import com.itheima.mall.service.OssService;
import com.itheima.mall.template.OssTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/aliyun")
public class OssController {

    @Autowired
    private OssService ossService;

    /**
     * 图片上传
     */
    @PostMapping("/oss/upload")
    public ResponseEntity<Map<String,String>> upload(MultipartFile photoFile){
        String path = ossService.upload(photoFile);
        Map<String,String> map = new HashMap<>();
        map.put("url",path);
        return ResponseEntity.ok(map);
    }


}
